# -*- coding: utf-8 -*-

import json
import os

CURRENT_PATH = os.path.dirname(os.path.abspath(__file__))
SAVE_PATH = os.path.join(CURRENT_PATH, 'images')

with open('cache.json') as f:
    cache = json.load(f)
assert 'posts' in cache and 'images' in cache
for column, posts in cache['posts'].items():
    column_path = os.path.join(SAVE_PATH, column)
    # if not os.path.exists(column_path):
    #     os.mkdir(column_path)
    # continue
    for post in posts:
        post_name = post['name']
        old_path = os.path.join(SAVE_PATH, post_name)
        new_path = os.path.join(SAVE_PATH, u'【%s】%s' % (column, post_name))
        if os.path.exists(old_path):
            print old_path
            print '>>>', new_path
            os.rename(old_path, new_path)
